package com.yingda.utils;

import android.text.TextUtils;

import com.yingda.bean.WorkBean;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtils {
    private static RegexUtils instance;
    private List<WorkBean> workBeans = new ArrayList<>();
    private RegexUtils () {}

    public static RegexUtils getInstance() {
        if (instance == null) {
            instance = new RegexUtils();
        }
        return instance;
    }

    public List<WorkBean> regexWord(String content) {
        workBeans.clear();
        // 正则表达式，匹配姓名和编号
        String regex = "([\\u4e00-\\u9fa5]{2,4})\\s*(\\d{6})";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(content);

        // 遍历所有匹配的结果
        while (matcher.find()) {
            String name = matcher.group(1);  // 第一个捕获组：姓名
            String number = matcher.group(2);  // 第二个捕获组：编号
            System.out.println("姓名: " + name + ", 编号: " + number);
            WorkBean workBean = new WorkBean();
            workBean.setName(name);
            if (!TextUtils.isEmpty(number)){
                int num = Integer.parseInt(number);
                String paddedNumber = String.format("%010d", num); // 数字前补0，补足10位
                workBean.setId(paddedNumber);
            }

            workBeans.add(workBean);
        }
        return workBeans;
    }



}
